//
//  BaseTabbarViewController.swift
//  TodayHistory
//
//  Created by RYX on 2018/12/5.
//  Copyright © 2018年 tuobu. All rights reserved.
//

import UIKit

class BaseTabbarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tabBar.tintColor = UIColor.white
        self.tabBar.barTintColor = UIColor.black
        
        bulidTabBar()
    }
}

extension BaseTabbarViewController{
    
    func bulidTabBar() -> Void {
        
        self.setupChildViewController(title: "首页", controller: HeaderViewController(), normalImg: "first_normal", selectImg: "first_selected")
        self.setupChildViewController(title: "我的", controller: MineViewController(), normalImg: "four_normal", selectImg: "four_selected")
    }
    
    func setupChildViewController(title:String,controller:UIViewController,normalImg:String,selectImg:String) -> Void {
        
        let item = UITabBarItem.init()
        item.image = UIImage(named: normalImg)
        item.selectedImage = UIImage(named: selectImg)
        item.title = title
        
        controller.tabBarItem = item
        controller.title = title
        let navController = BaseNavigationViewController.init(rootViewController: controller)
        navController.navigationBar.backgroundColor = UIColor.white

        let dict:NSDictionary = [NSAttributedString.Key.foregroundColor: UIColor.white,NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 18)]
        navController.navigationBar.titleTextAttributes = dict as? [NSAttributedString.Key : AnyObject]
        navController.navigationBar.tintColor = UIColor.red
        navController.navigationBar.barTintColor = UIColor.black
        self.addChild(navController)
    }
}
